import js from '@eslint/js'; // 官方 JS 规则
import tseslint from 'typescript-eslint';
import vue from 'eslint-plugin-vue';

export default [
  // 默认规则，适用所有文件
  {
    ignores: ['node_modules', 'dist'],
  },

  // JS/TS 通用规则
  {
    files: ['**/*.js', '**/*.ts'],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
    },
    rules: {
      ...js.configs.recommended.rules, // ESLint 官方规则
    },
  },

  // TS 专用规则
  {
    files: ['**/*.ts'],
    ...tseslint.configs.recommended,
  },

  // apps/frontend (Vue 项目)
  {
    files: ['apps/frontend/**/*.{ts,js,vue}'],
    languageOptions: {
      parser: 'vue-eslint-parser',
      parserOptions: {
        parser: '@typescript-eslint/parser',
        ecmaVersion: 'latest',
        sourceType: 'module',
      },
    },
    plugins: { vue },
    rules: {
      ...vue.configs['vue3-recommended'].rules,
    },
  },
  // apps/backend (Node 项目)
  {
    files: ['apps/backend/**/*.ts'],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
    },
    rules: {
      ...js.configs.recommended.rules,
      'no-console': 'off', // 允许 console.log
    },
  },
  // packages/utils (纯 TS 工具库)
  {
    files: ['packages/utils/**/*.ts'],
    ...tseslint.configs.recommended,
    rules: {
      '@typescript-eslint/no-explicit-any': 'warn', // 更严格
    },
  },
];
